package cn.doitedu.dfdemo

import cn.doitedu.util.SparkUtil
import org.apache.spark.sql.types.{DataTypes, StructType}

/**
 * @Date 22.4.9
 * @Created by HANGGE
 * @Description
 *
 */
object C01_MakeDF_Json_Row {
  def main(args: Array[String]): Unit = {
    val session = SparkUtil.getSession
    val df = session.read.json("data/json/user.json")
    session.udf.register("hello" ,(x:String)=>"hello: "+x )
    df.createOrReplaceTempView("tb_x")


    session.sql("select * , hello(name) from  tb_x").show()


    /**
     * root
     * |-- age: long (nullable = true)
     * |-- gender: string (nullable = true)
     * |-- id: long (nullable = true)
     * |-- name: string (nullable = true)
     *
     * 以某行中最多属性为基准
     * 其他行中没有某个属性   补null
     * +----+------+---+----+
     * | age|gender| id|name|
     * +----+------+---+----+
     * |  23|     M|  1| zss|
     * |  33|     M|  2| lss|
     * |null|     M|  3|  ww|
     * +----+------+---+----+
     */
  /*  df.printSchema()
    df.show()*/
  }

}
